package cst.start.fragmenttest128lqn.Fragment;


import android.content.Context;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import java.util.List;

import cst.start.fragmenttest128lqn.R;
import cst.start.fragmenttest128lqn.adapter.MyAdapter;
import cst.start.fragmenttest128lqn.bean.ArticleBean;
import cst.start.fragmenttest128lqn.iface.ArticleListener;
import cst.start.fragmenttest128lqn.model.ArticleModel;

/**
 * A simple {@link Fragment} subclass.
 */
public class WeixinFragment extends Fragment {
    private View view;
    private Context context;
    RecyclerView recyclerView;
    RecyclerView.LayoutManager layoutManager;
    MyAdapter mAdapter;
    List<ArticleBean> list;
    ArticleListener articleListener = new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> blist) {
            list=blist;
            mAdapter.setList(list);
        }

        @Override
        public void onFail(String msg) {
         Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
        }
    };


    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState) {
        context=getActivity();
        //动态加载wfragment的布局文件
        view=inflater.inflate(R.layout.wfragment,container,false);
        //获取布局上的控件，通过view获取
//        tvinfo=(TextView)view.findViewById(R.id.wtextView);
//        tvinfo.setText("微信");
        recyclerView=(RecyclerView)view.findViewById(R.id.recyclerview);
        layoutManager=new LinearLayoutManager(context);
        recyclerView.setLayoutManager(layoutManager);

        mAdapter=new MyAdapter(context);
        mAdapter.setList(list);
        recyclerView.setAdapter(mAdapter);

        ArticleModel articleModel = new ArticleModel();
        articleModel.getResultList("article",2,"k17vmm42ui9al6clh0lo3de2t7",articleListener);
        Toast.makeText(context,"加载微信...",Toast.LENGTH_SHORT).show();

        return view;
    }
}
